#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <stdint.h>

typedef struct {
	void *node;

	uint32_t number_of_allocated_block;
	uint32_t magic;
} heap_cache_t;

int main(int argc, char *argv[]) {
	if(argc != 2) {
		printf("Usage: %s<size_per_block>\n", argv[0]);
		return 1;
	}

	int size_per_block = atoi(argv[1]);

	if(size_per_block <= 0 || size_per_block > USHRT_MAX) {
		printf("Invalid input\n");
		return 1;
	}

	uint32_t actual_size_per_block = size_per_block + sizeof(uint32_t);

	for(uint64_t np = 1;; ++np) {
		uint64_t available = (np << 12) - sizeof(heap_cache_t);

		printf("np=%ld, loss=%ld, blk_cnt=%ld\n", np, available % actual_size_per_block, available / actual_size_per_block);

		if(available % actual_size_per_block <= actual_size_per_block / 4 && available / actual_size_per_block >= 100) {
			printf("best np=%ld\n", np);

			break;
		}
	}

	return 0;
}
